package com.leetcode.题库.score1;

import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: com.leetcode.题库.score1
 * @Author: lei
 * @CreateTime: 2024-03-12  17:23
 * @Description: 输入两个字符串S和L，都只包含英文小写字母。S长度<=100，L长度<=500.000.判定S是否是L的有效子串。
 * @Version: 1.0
 */
public class 字符串序列判定 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            String l = scanner.nextLine();
            int result = -1;
            if (!matchWord(s, l)) break;
            char[] sChars = s.toCharArray();
            char[] lChars = l.toCharArray();
            for (int i = 0; i < sChars.length; i++) {
                String sChar = String.valueOf(sChars[i]);
                for (int j = i; j < lChars.length; j++) {
                    String lChar = String.valueOf(lChars[j]);
                    if (sChar.equals(lChar)) {
                        if (i == sChars.length - 1) {
                            result = j;
                            System.out.println(result);
                        }
                        break;
                    }
                }
            }
        }
    }

    private static boolean matchWord(String s, String l) {
        boolean sBoolean = Pattern.compile("[a-z]").matcher(s).find();
        boolean lBoolean = Pattern.compile("[a-z]").matcher(l).find();
        return (sBoolean && lBoolean);
    }
}
